package com.jet.goods.controller;

import com.jet.core.model.vo.PageVo;
import com.jet.core.result.ResultJson;
import com.jet.goods.domain.dto.TagDto;
import com.jet.goods.domain.entity.GoodsTag;
import com.jet.goods.domain.query.TagQuery;
import com.jet.goods.service.IGoodsTagService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods/tag")
public class TagController {

    private final IGoodsTagService goodsTagService;

    public TagController(IGoodsTagService goodsTagService) {
        this.goodsTagService = goodsTagService;
    }

    @PostMapping
    public ResultJson<Void> create(@RequestHeader long merchantNo,
                                   @RequestHeader long storeNo,
                                   @RequestHeader String accountId,
                                   @RequestBody @Validated TagDto dto) {
        goodsTagService.create(merchantNo, dto);
        return ResultJson.ok();
    }

    @PutMapping("/{id}")
    public ResultJson<Void> edit(@RequestHeader long merchantNo,
                                 @RequestHeader long storeNo,
                                 @RequestHeader String accountId,
                                 @PathVariable("id") String id,
                                 @RequestBody @Validated TagDto dto) {
        goodsTagService.edit(merchantNo, id, dto);
        return ResultJson.ok();
    }

    @DeleteMapping("/{id}")
    public ResultJson<Void> delete(@RequestHeader long merchantNo,
                                   @RequestHeader long storeNo,
                                   @RequestHeader String accountId,
                                   @PathVariable("id") String id) {
        goodsTagService.removeById(id);
        return ResultJson.ok();
    }

    @GetMapping("/{id}")
    public ResultJson<GoodsTag> info(@RequestHeader long merchantNo,
                                     @RequestHeader long storeNo,
                                     @RequestHeader String accountId,
                                     @PathVariable("id") String id) {
        return ResultJson.ok(goodsTagService.getById(id));
    }

    @GetMapping("/page")
    public ResultJson<PageVo<GoodsTag>> page(@RequestHeader long merchantNo,
                                             @RequestHeader long storeNo,
                                             @RequestHeader String accountId,
                                             TagQuery query) {
        return ResultJson.ok(goodsTagService.page(merchantNo, null, query));
    }
}
